/*
#####Read ME FIRST#####
First make sure to download and save all of the files 
from the Roper Center as listed in the readme.txt

Next, make sure to change the cd below to the
main directory where you have saved these files.

Reminder: Within the larger "Pew Data" main folder
you will have saved to larger directories, for each of these
data ("Pew Threat" and "Pew Priority").  Within each of these
two directories, you will have three subfolders "Pew Data" (where
the uncoded .dta files are held), "DO files" (where the 
Stata .do files are held to recode the uncoded .dta files)
and "Individual Recoded Pew Files" (where the smaller 
recoded files are held).  You will need to have all of the data
saved properly and the placed in the propor file structure for
this code to work.
*/


dropbox
cd "Asymmetric Polarization/Pew Data"

***********************Threat Data************
***Recode Threat Data
do "Pew Threat/DO Files/Pew_2009_November Coding.do"
do "Pew Threat/DO Files/Pew_2012_May Coding.do"
do "Pew Threat/DO Files/Pew_2013_November Coding.do"
do "Pew Threat/DO Files/Pew_2014_August Coding.do"
do "Pew Threat/DO Files/Pew_2015_December Coding.do"
do "Pew Threat/DO Files/Pew_2016_April Coding.do"
do "Pew Threat/DO Files/Pew_2017_Jan Coding.do"
do "Pew Threat/DO Files/Pew_2019_Jan Coding.do"
do "Pew Threat/DO Files/Pew_2020_Mar Coding.do"

***Make cumulative file
use "Pew Threat/Individual Recoded Pew Files/Pew_2009_November_Recode.dta", clear
append using "Pew Threat/Individual Recoded Pew Files/Pew_2012_May_Recode.dta"
append using "Pew Threat/Individual Recoded Pew Files/Pew_2013_November_Recode.dta"
append using "Pew Threat/Individual Recoded Pew Files/Pew_2014_August_Recode.dta"
append using "Pew Threat/Individual Recoded Pew Files/Pew_2015_December_Recode.dta"
append using "Pew Threat/Individual Recoded Pew Files/Pew_2016_April_Recode.dta"
append using "Pew Threat/Individual Recoded Pew Files/Pew_2017_Jan_Recode.dta"
append using "Pew Threat/Individual Recoded Pew Files/Pew_2019_Jan_Recode.dta"
append using "Pew Threat/Individual Recoded Pew Files/Pew_2020_Mar_Recode.dta"

recode cohort ///
	(1/6=6) ///
	(20/21=20)

la def cohort ///
	1 " " 2 " " 3 " " 4 " " 5 " " ///
	6 "<1929" 7 "1930-1934" 8 "1935-1939" ///
	9 "1940-1944" 10 "1945-1949" 11 "1950-1954" 12 "1955-1959" ///
	13 "1960-1964" 14 "1965-1969" 15 "1970-1974" 16 "1975-1979" ///
	17 "1980-1984" 18 "1985-1989" 19 "1990-1994" 20 ">1995", modify
la var cohort "Age Cohort, 5 yr. intervals"
la val cohort cohort

recode CCthreat ///
	(3=1 "Major Threat") ///
	(2 1=0 "Not Major Threat"), ///
	gen(cc_threat)
la var cc_threat "Climate Change Threat"
	
save "Pew Combined Threat 2009-2020.dta", replace

***********************Priority Data************
***Recode Priority Data
do "Pew Priority/DO Files/Pew_2001_Oct Coding.do"
do "Pew Priority/DO Files/Pew_2004_July Coding.do"
do "Pew Priority/DO Files/Pew_2007_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2008_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2009_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2010_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2011_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2012_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2013_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2014_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2015_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2016_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2017_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2018_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2019_Jan Coding.do"
do "Pew Priority/DO Files/Pew_2020_Jan Coding.do"


***Make cumulative file
use "Pew Priority/Individual Recoded Pew Files/Pew_2001_Oct_Recode.dta", clear
append using "Pew Priority/Individual Recoded Pew Files/Pew_2004_July_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2007_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2008_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2009_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2010_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2011_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2012_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2013_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2014_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2015_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2016_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2017_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2018_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2019_Jan_Recode.dta"
append using "Pew Priority/Individual Recoded Pew Files/Pew_2020_Jan_Recode.dta"
drop CCseriousness density

recode cohort ///
	(1/5=5) ///
	(20/21=20)

la def cohort ///
	1 " " 2 " " 3 " " 4 " " ///
	5 "<1924" 6 "1925-1929" 7 "1930-1934" 8 "1935-1939" ///
	9 "1940-1944" 10 "1945-1949" 11 "1950-1954" 12 "1955-1959" ///
	13 "1960-1964" 14 "1965-1969" 15 "1970-1974" 16 "1975-1979" ///
	17 "1980-1984" 18 "1985-1989" 19 "1990-1994" 20 ">1995", modify
la var cohort "Age Cohort, 5 yr. intervals"
la val cohort cohort


recode CCpriority3 ///
	(3=1 "Top Priority") ///
	(2 1=0 "Not Top Priority"), ///
	gen(drop_cc_priority3)

recode CCpriority ///
	(4=1 "Top Priority") ///
	(3 2 1=0 "Not Top Priority"), ///
	gen(drop_cc_priority)
	
egen cc_priority=rowtotal(drop_cc_priority3 drop_cc_priority), m
drop drop_*	
la var cc_priority "Climate Change Priority"

save "Pew Combined Priority 2001-2020.dta", replace

//Combine into one file
append using "Pew Combined Threat 2009-2020.dta"

gen data=2
la def data 1 "GSS" 2 "Pew" 3 "Gallup"
la val data data

rename partyid partyid3

keep ///
	data year cohort id ///
	cc_priority cc_threat ///
	partyid3 education ///
	age female race south 


dropbox
cd "Asymmetric Polarization"
save "data/individual/Pew_2001_2021_recode.dta", replace


